﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GoldDigger.Models
{
    public class ItemsetModel
    {
        public double SupportVal { get; set; }
        public int SupportCount { get; set; }
        public List<string> ItemList { get; set; }

        public ItemsetModel(List<string> list)
        {
            ItemList = list;
            SupportVal = 0d;
            SupportCount = 0;
        }

        //method to check if itemset is member of a list
        public bool In(List<ItemsetModel> list)
        {
            var inBool = false;
            //For every itemset in source list
            foreach (var o in list)
            {
                //if itemset string list is same lenth as this itemset string list
                if (o.ItemList.Count == ItemList.Count)
                {
                    var sameList = true;

                    for (int i = 0; i<ItemList.Count; i++)
                    {
                        //If strings differ, then lists are not same and break
                        if (!(o.ItemList[i] == ItemList[i]))
                        {
                            sameList = false;
                            break;
                        }
                    }

                    if (sameList)
                    {
                        inBool = true;
                        break;
                    }
                }
            }

            return inBool;
        }

        public ItemsetModel Clone()
        {
            var nwIs = new ItemsetModel(new List<string>());
            nwIs.SupportVal = SupportVal;
            nwIs.SupportCount = SupportCount;

            foreach (string s in ItemList)
                nwIs.ItemList.Add(s);

            return nwIs;
        }
    }
}
